home *** CD-ROM | disk | FTP | other *** search
/ Flash MX Savvy / FlashMX Savvy.iso / pc / MAC / Amapi3D / Amapi3DTrial_Edition / 3SPACE / BlinkBehavior.js < prev    next >
Encoding:
Text File  |  2001-02-20  |  1.7 KB  |  75 lines  |  [AMAS/AMAP]

  1. // -* BlinkBehavior.js *-
  2. //
  3. // Name: Blink behavior
  4. // Description: 
  5. // Author:
  6. // Version: $Id: BlinkBehavior.js,v 1.8 2000/12/21 15:03:30 consumer Exp $
  7. //
  8.  
  9. // Keep an array of the solids using this behavior
  10. var blinkSolids = new Array(1);
  11.  
  12. function BlinkBehavior(solidName, delay, geom)
  13. {
  14.   // Member methods of the behavior
  15.   this.start = BlinkBehaviorStart;
  16.   this.stop = BlinkBehaviorStop;
  17.  
  18.   // Make a new timer
  19.   this.timerId = TSMakeUniqID("Blink_" + solidName);
  20.   this.geomId = geom;
  21.   this.delay = delay;
  22.  
  23.   TSMakeTimerEvent(this.timerId, 0, delay, 'BlinkChangeState');
  24.   TSSetExtraParam(this.timerId, 'geom', geom);
  25.   TSAppendChild(solidName, this.timerId);
  26.   TSUpdateNode(this.timerId);
  27. }
  28.  
  29. function BlinkBehaviorStart()
  30. {
  31.   TSUpdateNodeAttribute(this.timerId, 'every', this.delay.toString());
  32. }
  33.  
  34. function BlinkBehaviorStop()
  35. {
  36.   TSUpdateNodeAttribute(this.timerId, 'every', '65535');
  37.   TSUpdateNodeAttribute(this.geomId, 'visible', '1');
  38. }
  39.  
  40. function BlinkChangeState(obj, event)
  41. {
  42.   var geom = TSGetExtraParam(event, 'geom');
  43.  
  44.   if (TSGetAttribute(geom, 'visible') == '1') {
  45.     TSUpdateNodeAttribute(geom, 'visible', '0');
  46.   } else {
  47.     TSUpdateNodeAttribute(geom, 'visible', '1');
  48.   }
  49. }
  50.  
  51. //
  52. // Event functions
  53. //
  54.  
  55. function BlinkBehaviorStartEvent(obj, event)
  56. {
  57.   if (blinkSolids[obj] == null) {
  58.     var delay = TSGetExtraParam(event, 'delay');
  59.     var geom = TSGetExtraParam(event, 'geom');
  60.     var targetSolid = TSGetExtraParam(event, 'targetSolid');
  61.  
  62.     if (targetSolid == "")
  63.       blinkSolids[obj] = new BlinkBehavior(obj, delay, geom);
  64.     else
  65.       blinkSolids[obj] = new BlinkBehavior(targetSolid, delay, geom);
  66.   }
  67.  
  68.   blinkSolids[obj].start();
  69. }
  70.  
  71. function BlinkBehaviorStopEvent(obj, event)
  72. {
  73.   blinkSolids[obj].stop();
  74. }
  75.